package com.yxc.eslibrary.http;

import java.util.*;

/**
 * Created by robin on 15-9-7.
 */
public class CommonParams {
    private Map<String, String> commonParamMap = new HashMap<String, String>();
    private Map<String,HttpHeader> commonHeaders = new HashMap<String, HttpHeader>();

    private static CommonParams ourInstance;

    public static CommonParams getInstance() {
        if (ourInstance==null){
            ourInstance = new CommonParams();
        }
        return ourInstance;
    }

    private CommonParams() {
    }

    public static void addCommonParam(String key, String value){
        CommonParams commonParams = getInstance();
        commonParams.commonParamMap.put(key, value);
    }

    public static void removeCommonParam(String key){
        CommonParams commonParams = getInstance();
        commonParams.commonParamMap.remove(key);
    }

    public static void addCommonHeader(HttpHeader header){
        CommonParams commonParams = getInstance();
        commonParams.commonHeaders.put(header.getKey(), header);
    }

    public static void removeCommonHeader(String headerKey){
        CommonParams commonParams = getInstance();
        commonParams.commonHeaders.remove(headerKey);
    }

    public static void removeCommonHeader(HttpHeader header){
        removeCommonHeader(header.getKey());
    }

    public static Collection<HttpHeader> getCommonHeaders(){
        CommonParams commonParams = getInstance();
        return commonParams.commonHeaders.values();
    }

    public static Map<String, String> getCommonParams() {
        CommonParams commonParams = getInstance();
        return commonParams.commonParamMap;
    }
}
